package factoryMode.factory.abstractFactory.order;

import factoryMode.factory.abstractFactory.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author： pang-yun
 * @date： 2021-10-21 22:20
 * 功能目的 ：用于
 */

public class OrderPizza {
    AbstractFactory factory;


    public OrderPizza(AbstractFactory factory){
        setFactory(factory);
    }


    private void setFactory(AbstractFactory factory){
        Pizza pizza =null;
        String orderType;
        this.factory = factory;

        do {
            orderType=getType();
            pizza = factory.createPizza(orderType);

            if (pizza!=null){
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }else {
                System.out.println("订购失败");
                break;
            }


        }while (true);
    }





    //从控制台 获取想订购pizza 的种类
    private String getType() {
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("输入pizza种类:");
            String s = reader.readLine();
            return s;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
